#include "secondplugin.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QSlider>

QString SecondPlugin::name() const
{
    return "Second Plugin";
}

QWidget* SecondPlugin::createWidget(QWidget* parent)
{
    QWidget* widget = new QWidget(parent);
    QVBoxLayout* layout = new QVBoxLayout(widget);
    
    QLabel* label = new QLabel("这是第二个插件的界面", widget);
    
    // 初始化infoLabel
    infoLabel = new QLabel("共享变量: 未设置", widget);
    
    QLabel* valueLabel = new QLabel("值: 50", widget);
    QSlider* slider = new QSlider(Qt::Horizontal, widget);
    slider->setRange(0, 100);
    slider->setValue(50);
    
    QObject::connect(slider, &QSlider::valueChanged, [valueLabel](int value) {
        valueLabel->setText(QString("值: %1").arg(value));
    });
    
    layout->addWidget(label);
    layout->addWidget(infoLabel);
    layout->addWidget(slider);
    layout->addWidget(valueLabel);
    layout->addStretch();
    
    return widget;
}

void SecondPlugin::setSharedValue(const QString& value)
{
    // 安全地设置共享值，检查infoLabel是否已初始化
    if (infoLabel) {
        infoLabel->setText(QString("共享变量: %1").arg(value));
    }
}